package Controller.BDD;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class GestionnaireRequeteBDD {

	public Connection getConnexion(){
		//System.out.println("-------- PostgreSQL JDBC Connection Testing ------------"); 

		//JUSTE POUR TESTER SI LE DRIVER EST LA
		try { 
			Class.forName("org.postgresql.Driver"); 
		}
		catch (ClassNotFoundException e){ 
			System.out.println("Where is your PostgreSQL JDBC Driver? Include in your library path!"); 
			e.printStackTrace(); 
		} 
		//System.out.println("PostgreSQL JDBC Driver Registered!"); 


		Connection connection = null; 
		try{ 
			connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/ASDESCOURS","postgres", "postgres");
			return connection;
		}
		catch (SQLException e){ 
			System.out.println("Connection Failed! Check output console"); 
			e.printStackTrace();
			return null;
		} 
	}

	public void resetConnexion(Connection connection){
		if(connection!=null){
			try{
				connection.close();
			}catch(Exception e)
			{
				e.printStackTrace();
			}
		}

	}
}
